var loginid,loginuser,loginname,loginkey;
var isjump = 0;//控制翻页
var layer,$,laypage,element,form,loadmsg,jointraderid;
var jumpobj;//跳转对象(page_horder 订单信息,page_hcomm 提成信息,page_hcard 卡库信息,
//page_buycard 购卡信息 ,page_sendcard 售卡信息,page_commask 提成申请）
var alertmsg = "";
var initdata=[];
layui.config({
	version:'1510164124181'
}).use(['form', 'laypage', 'layer', 'element'],function(){
	form = layui.form;
	layer = layui.layer;
	$ = layui.jquery;
    laypage = layui.laypage;//分页
    element = layui.element; //元素操作
	loginid = $.session.get("userid");
	loginuser = $.session.get("admin_realname");
	loginname = $.session.get("username");
	loginkey = $.session.get("user_secretkey");
	jointraderid = $.session.get("jointraderid");
	find_store();
});
//初始化数据
function initdatas(){
	//console.log("['" + loginname + "','" + loginkey + "',"+(jointraderid*1)+"]");
    var index = top.layer.msg('加载中，请稍候',{icon: 16,time:false,shade:0.8});
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_userall_selbyid",
			para: "['" + loginname + "','" + loginkey + "',"+(jointraderid*1)+"]"
		},
		dataType: "json",
		success: function(data) {
			top.layer.closeAll();
			//console.log(JSON.stringify(data))
			if(data[0].TAG=='0'){
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
			    });
			}else if(data[0].TAG=='2'){
			   layer.msg(""+data[0].MSG+"");
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
			}else{
			   $("#hname").val(data[0].HNAME);
			   $("#hidcard").val(data[0].HIDCARD);
			   $("#htel").val(data[0].HTEL);
			   $("#shop_id").val(data[0].SHOP_ID);
			   $("#royalty_ratio").val(data[0].ROYALTY_RATIO);
			   $("#h_password").val(data[0].H_PASSWORD);
			  $("input[name='mm'][value='"+data[0].OPEN_XS+"']").attr("checked",true);
			}

		}
	});
}
//查询所有的店铺
function find_store(){
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.store_selall",
			para: "['" + loginname + "','" + loginkey + "',99999999,1]"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			var dataHtml='<option value="-1">请选择店铺</option>';
			if(data[0].TAG=='0'){
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
			    });
			}else if(data[0].TAG=='2'){
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
			}else{
				for(var i=0;i<data.length;i++){
					if(i==data.length-1){
					}else{
						dataHtml += '<option value="'+data[i].ID+'">'+data[i].SHOP_NAME+'</option>';
					}
				}
			}
			$("#shop_id").html(dataHtml);
			initdatas();
		}

	});
}
//查询当前选择店铺的人员
function find_storepecount(obj){
	var storeid = $(obj).val();
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_userall_selbystore",
			para: "['" + loginname + "','" + loginkey + "','"+storeid+"']"
		},
		dataType: "json",
		success: function(data) {
			console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
			    });
			}else if(data[0].TAG=='2'){
				 top.layer.msg(""+data[0].MSG+"");
				 $("#shop_id").val("-1");
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				 top.layer.msg("系统错误，请重试！");
				 $("#shop_id").val("-1");
			}
		}

	});
}
//修改管家
function update(){
	var hname = $("#hname").val().replace(/(^\s+)|(\s+$)/g, "");
	if (hname == '') {
		layer.msg("请输入姓名!",{icon:2});
		return;
	}
	if (!checkChinese(hname)) {
		layer.msg("请输入汉字，并且长度为2-4位!",{icon:2});
		return;
	}
	var firstName = hname.substr(0, 1);
	if (!checkbjx(firstName)) {
		layer.msg("请输入百家姓姓名!",{icon:2});
		return;
	}
	var hidcard = $("#hidcard").val();
	if(!IdentityCodeValid(hidcard)){
		layer.msg("身份证号错误!",{icon:2});
		return;
	};
	var htel = $("#htel").val();
	var regPartton=/1[3-8]+\d{9}/;
	if(!htel || htel==null || !regPartton.test(htel)){
		layer.msg("手机号码格式不正确！",{icon:2});
		$("#htel").focus();return;
	}
	var shop_id = $("#shop_id").val();
	if(shop_id=='-1'){
		layer.msg("请选择店铺！",{icon:2});
		return;
	}
	var royalty_ratio = $("#royalty_ratio").val();
	if(isNaN(royalty_ratio) || royalty_ratio==''){
		layer.msg("请输入数字！",{icon:2});
		$("#royalty_ratio").focus();return;
	}
	var h_password = $("#h_password").val().replace(/(^\s+)|(\s+$)/g, "");
    if(h_password.length==0 || h_password==""){
		h_password='88888888';
	}
	var open_xs=$("input[name='mm']:checked").val();
    top.layer.confirm('您确定要修改此加盟商小二吗？',{icon: 3,title:'提示信息'},function(index){
		var index = top.layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
		setTimeout(function(){
			$.ajax({
				url: "../../../../service",
				cache: false,
				data: {
					proc: "c_admin.h_user_ediet",
					para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+hname+"','"+hidcard+"','"+htel+"','"+shop_id+"','"+royalty_ratio+"','"+h_password+"','"+open_xs+"']"
				},
				dataType: "json",
				success: function(data) {
					//console.log("====="+JSON.stringify(data));
					if(data[0].TAG=='0'){
						top.layer.closeAll();
						top.layer.alert(""+data[0].MSG+"",function(index){
						   top.location.href="login.html";
						   layer.close(index);
					    });
					}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
						top.layer.closeAll();
						top.layer.msg("修改失败，请检查您的网络环境!");
						console.log("读取接口失败,参数错误");
					}else if(data[0].TAG == 2){
						top.layer.msg(""+data[0].MSG+"");
					}else{
						top.layer.closeAll();
						top.layer.msg(""+data[0].MSG+"");
						returnlist();
					}
				}
			});
		},1000);
	})
}
//验证百家姓
function checkbjx(name) {
	//js正则表达式  match
	//为什么此时的match方法不对
	if ("赵|钱|孙|李|周|吴|郑|王|冯|陈|楮|卫|蒋|沈|韩|杨|朱|秦|尤|许|何|吕|施|张|孔|曹|严|华|金|魏|陶|姜|戚|谢|邹|喻|柏|水|窦|章|云|苏|潘|葛|奚|范|彭|郎|鲁|韦|昌|马|苗|凤|花|方|俞|任|袁|柳|酆|鲍|史|唐|费|廉|岑|薛|雷|贺|倪|汤|滕|殷|罗|毕|郝|邬|安|常|乐|于|时|傅|皮|卞|齐|康|伍|余|元|卜|顾|孟|平|黄|和|穆|萧|尹|姚|邵|湛|汪|祁|毛|禹|狄|米|贝|明|臧|计|伏|成|戴|谈|宋|茅|庞|熊|纪|舒|屈|项|祝|董|梁|杜|阮|蓝|闽|席|季|麻|强|贾|路|娄|危|江|童|颜|郭|梅|盛|林|刁|锺|徐|丘|骆|高|夏|蔡|田|樊|胡|凌|霍|虞|万|支|柯|昝|管|卢|莫|经|房|裘|缪|干|解|应|宗|丁|宣|贲|邓|郁|单|杭|洪|包|诸|左|石|崔|吉|钮|龚|程|嵇|邢|滑|裴|陆|荣|翁|荀|羊|於|惠|甄|麹|家|封|芮|羿|储|靳|汲|邴|糜|松|井|段|富|巫|乌|焦|巴|弓|牧|隗|山|谷|车|侯|宓|蓬|全|郗|班|仰|秋|仲|伊|宫|宁|仇|栾|暴|甘|斜|厉|戎|祖|武|符|刘|景|詹|束|龙|叶|幸|司|韶|郜|黎|蓟|薄|印|宿|白|怀|蒲|邰|从|鄂|索|咸|籍|赖|卓|蔺|屠|蒙|池|乔|阴|郁|胥|能|苍|双|闻|莘|党|翟|谭|贡|劳|逄|姬|申|扶|堵|冉|宰|郦|雍|郤|璩|桑|桂|濮|牛|寿|通|边|扈|燕|冀|郏|浦|尚|农|温|别|庄|晏|柴|瞿|阎|充|慕|连|茹|习|宦|艾|鱼|容|向|古|易|慎|戈|廖|庾|终|暨|居|衡|步|都|耿|满|弘|匡|国|文|寇|广|禄|阙|东|欧|殳|沃|利|蔚|越|夔|隆|师|巩|厍|聂|晁|勾|敖|融|冷|訾|辛|阚|那|简|饶|空|曾|毋|沙|乜|养|鞠|须|丰|巢|关|蒯|相|查|后|荆|红|游|竺|权|逑|盖|益|桓|公|万俟|司马|上官|欧阳|夏侯|诸葛|闻人|东方|赫连|皇甫|尉迟|公羊|澹台|公冶|宗政|濮阳|淳于|单于|太叔|申屠|公孙|仲孙|轩辕|令狐|锺离|宇文|长孙|慕容|鲜于|闾丘|司徒|司空|丌官|司寇|仉|督|子车|颛孙|端木|巫马|公西|漆雕|乐正|壤驷|公良|拓拔|夹谷|宰父|谷梁|晋|楚|阎|法|汝|鄢|涂|钦|段干|百里|东郭|南门|呼延|归|海|羊舌|微生|岳|帅|缑|亢|况|后|有|琴|梁丘|左丘|东门|西门|商|牟|佘|佴|伯|赏|南宫|墨|哈|谯|笪|年|爱|阳|佟|第五|言|福".search(name) != -1
	) {
		return true;
	}
	else {
		return false;
	}
}
//校验只能输入汉字，并且长度为2-4
function checkChinese(name) {

	reg = /^[\u4E00-\u9FA5]{2,4}$/;

	if (reg.test(name)) {

		return true;
	} else {
		return false;

	}

}
//验证身份证
function IdentityCodeValid(code) {
	var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
	var tip = "";
	var pass= true;

	if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
		tip = "身份证号格式错误";
		pass = false;
	}

   else if(!city[code.substr(0,2)]){
		tip = "地址编码错误";
		pass = false;
	}
	else{
		//18位身份证需要验证最后一位校验位
		if(code.length == 18){
			code = code.split('');
			//∑(ai×Wi)(mod 11)
			//加权因子
			var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
			//校验位
			var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
			var sum = 0;
			var ai = 0;
			var wi = 0;
			for (var i = 0; i < 17; i++)
			{
				ai = code[i];
				wi = factor[i];
				sum += ai * wi;
			}
			var last = parity[sum % 11];
			if(parity[sum % 11] != code[17]){
				tip = "校验位错误";
				pass =false;
			}
		}
	}
   return pass;

}
//订单信息
function order1(){
	pageNo = 1;
	isjump = 0;
	jumpobj = 'page_horder';
	order();
}
function order(){
	//console.log("['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+pageRecords+"','"+pageNo+"']");
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_user_order",
			para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+pageRecords+"','"+pageNo+"']"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				initdata=[];
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
				   top.layer.closeAll();
			       layer.closeAll();
			    });
			}else if(data[0].TAG=='2'){
			    initdata=[];
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				initdata=[];
			}else{
			    initdata =data;
			}
			var dataHtml="";
			$(".conorder").html("");
			if(initdata.length==0){
				  totalRecords =0;
				  dataHtml += '<tr>'
					+'<td colspan="10" style="text-align:center;">未找到任何数据</td>'
					+'</tr>';
				page();
			}else{
				for(var i=0;i<initdata.length;i++){
					if(i==initdata.length-1){
						totalRecords = initdata[i].ID;
						totalPage = initdata[i].UPORDOWN;
					}else{
				   	var stl = 'text-primary';
					if(initdata[i].UPORDOWN==1){
						stl = 'text-success';
					}
                       dataHtml += '<tr class="'+stl+'">'
								+'<td align="center">'+initdata[i].ID+'</td>'
								+'<td align="center">'+initdata[i].ORDER_ID+'</td>'
								+'<td align="center">'+initdata[i].USERNAME+'</td>'
								+'<td align="center">'+initdata[i].USERPHONE+'</td>'
								+'<td align="center">'+initdata[i].SHOP_NAME+'</td>'
								+'<td align="center">'+initdata[i].ORDER_TIME+'</td>'
								+'<td align="center">'+(Math.floor(initdata[i].ORDERMONEY * 100) / 100)+'</td>'
                                +'<td align="center">'+initdata[i].PAYMENT_METHOD+'</td>'
                                +'<td align="center">'+initdata[i].BAG_ID+'</td>'
								+'<td align="center">'
                                +  '<a href="javascript:void(0)" onclick="h_ediet(this)" data-id="'+initdata[i].ID+'">编辑</a>'
								+'</td>'
								+'</tr>';
					}
				}
			}
			$(".conorder").html(dataHtml);
			top.layer.closeAll();
			layer.closeAll();
            //执行一个laypage实例,保证每个方法只进一次
            if(isjump==0){
				page();
			}
           isjump++;

		}

	});

}
//提成信息
function searchcomm(){
    var begintime = $("#begintimecomm").val();
	var endtime = $("#endtimecomm").val();
    var d1 = new Date(begintime.replace(/\-/g, "\/"));
	var d2 = new Date(endtime.replace(/\-/g, "\/"));
	if(begintime=="" || endtime==""){
		layer.msg("开始时间或者结束时间不能为空！",{icon:2});
	     return false;
	}
	if(begintime!=""&&endtime!=""&&d1 >=d2){
	     layer.msg("开始时间不能大于结束时间！",{icon:2});
	     return false;
	 }
	isjump=0;
	pageNo = 1;
	jumpobj = 'page_hcomm';
	hcomm();
}
function hcomm1(){
	pageNo = 1;
	isjump = 0;
	jumpobj = 'page_hcomm';
	hcomm();
}
function hcomm(){
    var begintime = $("#begintimecomm").val();
	var endtime = $("#endtimecomm").val();
	if(begintime.length==0 || endtime.length==0){
		begintime = '101';
		endtime = '101';
	}else{
	 var d1 = new Date(begintime.replace(/\-/g, "\/"));
	 var d2 = new Date(endtime.replace(/\-/g, "\/"));
	  if(begintime!=""&&endtime!=""&&d1 >=d2){
	     begintime = '101';
		 endtime = '101';
	     //layer.msg("开始时间不能大于结束时间！",{icon:2});
	     //return false;
	  }
	}
	//console.log("['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+begintime+"','"+endtime+"','"+pageRecords+"','"+pageNo+"']")
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_user_comm",
			para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+begintime+"','"+endtime+"','"+pageRecords+"','"+pageNo+"']"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				initdata=[];
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
				   top.layer.closeAll();
			       layer.closeAll();
			    });
			}else if(data[0].TAG=='2'){
			    initdata=[];
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				initdata=[];
			}else{
			    initdata =data;
			}
			var dataHtml="";
			$(".conkcomm").html("");
			if(initdata.length==0){
				  totalRecords =0;
				  dataHtml += '<tr>'
					+'<td colspan="5" style="text-align:center;">未找到任何数据</td>'
					+'</tr>';
				page();
			}else{
				for(var i=0;i<initdata.length;i++){
					if(i==initdata.length-1){
						totalRecords = initdata[i].ID;
						totalPage = initdata[i].REAL_NAME;
					}else{
						dataHtml += '<tr>'
								+'<td align="center">'+initdata[i].ID+'</td>'
						        +'<td align="center">'+initdata[i].VAL+'</td>'
						      	+'<td align="center">'+initdata[i].NUMS+'</td>'
							    +'<td align="center">'+(Math.floor(initdata[i].PAYMONEY * 100) / 100)+'</td>'
								+'<td align="center">'+initdata[i].TIMES+'</td>'
								+'</tr>';
					}
				}
			}
			$(".conkcomm").html(dataHtml);
			top.layer.closeAll();
			layer.closeAll();
            //执行一个laypage实例,保证每个方法只进一次
            if(isjump==0){
				page();
			}
           isjump++;

		}

	});

}

//卡库信息
function hcard1(){
	pageNo = 1;
	isjump = 0;
	jumpobj = 'page_hcard';
	hcard();
}
function hcard(){
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_cardnumbyhid",
			para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+pageRecords+"','"+pageNo+"']"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				initdata=[];
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
				   top.layer.closeAll();
			       layer.closeAll();
			    });
			}else if(data[0].TAG=='2'){
			    initdata=[];
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				initdata=[];
			}else{
			    initdata =data;
			}
			var dataHtml="";
			$(".conhcard").html("");
			if(initdata.length==0){
				  totalRecords =0;
				  dataHtml += '<tr>'
					+'<td colspan="3" style="text-align:center;">未找到任何数据</td>'
					+'</tr>';
				page();
			}else{
				for(var i=0;i<initdata.length;i++){
					if(i==initdata.length-1){
						totalRecords = initdata[i].ID;
						totalPage = initdata[i].VAL;
					}else{
                       dataHtml += '<tr>'
								+'<td align="center">'+initdata[i].ID+'</td>'
								+'<td align="center">'+(Math.floor(initdata[i].VAL * 100) / 100)+'</td>'
                                +'<td align="center">'+initdata[i].NUMS+'</td>'
								+'</tr>';
					}
				}
			}
			$(".conhcard").html(dataHtml);
			top.layer.closeAll();
			layer.closeAll();
            //执行一个laypage实例,保证每个方法只进一次
            if(isjump==0){
				page();
			}
           isjump++;

		}

	});

}
//购卡信息
function searchbuycard(){
    var begintime = $("#begintimebuycard").val();
	var endtime = $("#endtimebuycard").val();
    var d1 = new Date(begintime.replace(/\-/g, "\/"));
	var d2 = new Date(endtime.replace(/\-/g, "\/"));
	if(begintime=="" || endtime==""){
		layer.msg("开始时间或者结束时间不能为空！",{icon:2});
	     return false;
	}
	if(begintime!=""&&endtime!=""&&d1 >=d2){
	     layer.msg("开始时间不能大于结束时间！",{icon:2});
	     return false;
	 }
	isjump=0;
	pageNo = 1;
	jumpobj = 'page_buycard';
	buycard();
}
function buycard1(){
	pageNo = 1;
	isjump = 0;
	jumpobj = 'page_buycard';
	buycard();
}
function buycard(){
    var begintime = $("#begintimebuycard").val();
	var endtime = $("#endtimebuycard").val();
	if(begintime.length==0 || endtime.length==0){
		begintime = '101';
		endtime = '101';
	}else{
	 var d1 = new Date(begintime.replace(/\-/g, "\/"));
	 var d2 = new Date(endtime.replace(/\-/g, "\/"));
	  if(begintime!=""&&endtime!=""&&d1 >=d2){
	     begintime = '101';
		 endtime = '101';
	     //layer.msg("开始时间不能大于结束时间！",{icon:2});
	     //return false;
	  }
	}
	//console.log("['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+begintime+"','"+endtime+"','"+pageRecords+"','"+pageNo+"']")
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_buycardbyhid",
			para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+begintime+"','"+endtime+"','"+pageRecords+"','"+pageNo+"']"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				initdata=[];
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
				   top.layer.closeAll();
			       layer.closeAll();
			    });
			}else if(data[0].TAG=='2'){
			    initdata=[];
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				initdata=[];
			}else{
			    initdata =data;
			}
			var dataHtml="";
			$(".conbuycard").html("");
			if(initdata.length==0){
				  totalRecords =0;
				  dataHtml += '<tr>'
					+'<td colspan="5" style="text-align:center;">未找到任何数据</td>'
					+'</tr>';
				page();
			}else{
				for(var i=0;i<initdata.length;i++){
					if(i==initdata.length-1){
						totalRecords = initdata[i].ID;
						totalPage = initdata[i].REAL_NAME;
					}else{
						dataHtml += '<tr>'
								+'<td align="center">'+initdata[i].ID+'</td>'
						        +'<td align="center">'+initdata[i].VAL+'</td>'
						      	+'<td align="center">'+initdata[i].NUMS+'</td>'
							    +'<td align="center">'+(Math.floor(initdata[i].PAYMONEY * 100) / 100)+'</td>'
								+'<td align="center">'+initdata[i].TIMES+'</td>'
								+'</tr>';
					}
				}
			}
			$(".conbuycard").html(dataHtml);
			top.layer.closeAll();
			layer.closeAll();
            //执行一个laypage实例,保证每个方法只进一次
            if(isjump==0){
				page();
			}
           isjump++;

		}

	});

}
//售卡信息
function searchsendcard(){
    var begintime = $("#begintimesendcard").val();
	var endtime = $("#endtimesendcard").val();
    var d1 = new Date(begintime.replace(/\-/g, "\/"));
	var d2 = new Date(endtime.replace(/\-/g, "\/"));
	if(begintime=="" || endtime==""){
		layer.msg("开始时间或者结束时间不能为空！",{icon:2});
	     return false;
	}
	if(begintime!=""&&endtime!=""&&d1 >=d2){
	     layer.msg("开始时间不能大于结束时间！",{icon:2});
	     return false;
	 }
	isjump=0;
	pageNo = 1;
	jumpobj = 'page_sendcard';
	sendcard();
}
function sendcard1(){
	pageNo = 1;
	isjump = 0;
	jumpobj = 'page_sendcard';
	sendcard();
}
function sendcard(){
    var begintime = $("#begintimesendcard").val();
	var endtime = $("#endtimesendcard").val();
	if(begintime.length==0 || endtime.length==0){
		begintime = '101';
		endtime = '101';
	}else{
	 var d1 = new Date(begintime.replace(/\-/g, "\/"));
	 var d2 = new Date(endtime.replace(/\-/g, "\/"));
	  if(begintime!=""&&endtime!=""&&d1 >=d2){
	     begintime = '101';
		 endtime = '101';
	     //layer.msg("开始时间不能大于结束时间！",{icon:2});
	     //return false;
	  }
	}
	//console.log("['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+begintime+"','"+endtime+"','"+pageRecords+"','"+pageNo+"']")
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_sendcardbyhid",
			para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+begintime+"','"+endtime+"','"+pageRecords+"','"+pageNo+"']"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				initdata=[];
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
				   top.layer.closeAll();
			       layer.closeAll();
			    });
			}else if(data[0].TAG=='2'){
			    initdata=[];
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				initdata=[];
			}else{
			    initdata =data;
			}
			var dataHtml="";
			$(".consendcard").html("");
			if(initdata.length==0){
				  totalRecords =0;
				  dataHtml += '<tr>'
					+'<td colspan="5" style="text-align:center;">未找到任何数据</td>'
					+'</tr>';
				page();
			}else{
				for(var i=0;i<initdata.length;i++){
					if(i==initdata.length-1){
						totalRecords = initdata[i].ID;
						totalPage = initdata[i].REAL_NAME;
					}else{
						dataHtml += '<tr>'
								+'<td align="center">'+initdata[i].ID+'</td>'
						        +'<td align="center">'+initdata[i].VAL+'</td>'
						      	+'<td align="center">'+initdata[i].NUMS+'</td>'
								+'<td align="center">'+initdata[i].USER_PHONE+'</td>'
								+'<td align="center">'+initdata[i].TIMES+'</td>'
								+'</tr>';
					}
				}
			}
			$(".consendcard").html(dataHtml);
			top.layer.closeAll();
			layer.closeAll();
            //执行一个laypage实例,保证每个方法只进一次
            if(isjump==0){
				page();
			}
           isjump++;

		}

	});

}
//提成申请
function commask1(){
	pageNo = 1;
	isjump = 0;
	jumpobj = 'page_commask';
	commask();
}
function commask(){
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.h_depositask_selbyhid",
			para: "['" + loginname + "','" + loginkey + "',"+jointraderid+",'"+pageRecords+"','"+pageNo+"']"
		},
		dataType: "json",
		success: function(data) {
			//console.log(JSON.stringify(data));
			if(data[0].TAG=='0'){
				initdata=[];
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
				   top.layer.closeAll();
			       layer.closeAll();
			    });
			}else if(data[0].TAG=='2'){
			    initdata=[];
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
				initdata=[];
			}else{
			    initdata =data;
			}
			var dataHtml="";
			$(".concommask").html("");
			if(initdata.length==0){
				  totalRecords =0;
				  dataHtml += '<tr>'
					+'<td colspan="6" style="text-align:center;">未找到任何数据</td>'
					+'</tr>';
				page();
			}else{
				for(var i=0;i<initdata.length;i++){
					if(i==initdata.length-1){
						totalRecords = initdata[i].ASK_NUMBER;
						totalPage = initdata[i].U_ID;
					}else{
                       dataHtml += '<tr>'
								+'<td align="center">'+initdata[i].ASK_NUMBER+'</td>'
                                +'<td align="center">'+initdata[i].U_ID+'</td>'
								+'<td align="center">'+(Math.floor(initdata[i].DEPOSIT_MONEY * 100) / 100)+'</td>'
                                +'<td align="center">'+initdata[i].ASK_STATE+'</td>'
								+'<td align="center">'+initdata[i].DEPOSIT_TIME+'</td>'
								+'<td align="center">'+initdata[i].CHECK_TIME+'</td>'
								+'</tr>';
					}
				}
			}
			$(".concommask").html(dataHtml);
			top.layer.closeAll();
			layer.closeAll();
            //执行一个laypage实例,保证每个方法只进一次
            if(isjump==0){
				page();
			}
           isjump++;

		}

	});

}

//分页
function page(){
	laypage.render({
		elem: ''+jumpobj+'' //注意，这里的 test1 是 ID，不用加 # 号
		,count:totalRecords //数据总数，从服务端得到
		//,curr: pageNo //获取起始页 location.hash.replace('#!fenye=', '')
        //,hash: 'fenye' //自定义hash值
		,layout: ['count', 'prev', 'page', 'next', 'skip']
		,jump: function(obj, first){
			//首次不执行
			if(!first){
			  //console.log("当前页==="+obj.curr); //得到当前页，以便向服务端请求对应页的数据。
			  //console.log("每页显示条数==="+obj.limit); //得到每页显示的条数
			  pageNo = obj.curr;
			  if(jumpobj == 'page_sendcard'){
				  sendcard();
			  }else if(jumpobj=='page_buycard'){
				  buycard();
			  }else if(jumpobj=='page_commask'){
				  commask();
			  }else if(jumpobj=='page_hcard'){
				  hcard();
			  }else if(jumpobj=='page_horder'){
				 order();
			  }else if(jumpobj=='page_hcomm'){
				 hcomm();
			  }

			}
		  }
	});
}
//返回
function returnlist(){
	$.session.remove("jointraderid");
	window.location.href="jointrader_mentg.html";
}
